package com.wanbangee.marksystem.controller;
 
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.wanbangee.marksystem.entities.MExamMarker;
import com.wanbangee.marksystem.service.ProgressCheckService;
import com.wanbangee.marksystem.service.score.SettingScoreService;
import com.wanbangee.marksystem.service.score.UserCenterScoreService;

@RestController
@RequestMapping("progress")
public class ProgressCheckController {
	
	
	@Autowired
	private SettingScoreService settingScoreService;
	
	@Autowired
	private UserCenterScoreService userCenterScoreService;
	
	@Autowired
	private ProgressCheckService progressCheckService;
	
	/**
	 * 用于进度监控的列表显示界面
	 * @param examId
	 * @param examSubId
	 * @return
	 */
	@GetMapping("selectProgressList/{examId}/{examSubId}")
	public Map selectProgressList(@PathVariable("examId")Integer examId,@PathVariable("examSubId")Integer examSubId) {
		Map map = settingScoreService.selectProgressList(examId, examSubId);
		HashMap<String, Object> result = new HashMap<String, Object>();
		if(map != null) {
			result.put("code", 1001);
			result.put("result", map);
		}else {
			result.put("code", 10013);
			result.put("result", null);
		}
		
		return result;
	}
	/**
	 * 查询当前学校还未过期的考试id
	 * @param schId
	 * @param date 
	 * @return
	 */
	@GetMapping("selectExamId/{schId}/{date}")
	public Map selectExamId(@PathVariable("schId")Integer schId,@PathVariable("date")String date) {
		return settingScoreService.selectExamId(schId, date);
	}
	
	/**
	 * 根据考试 id 查询考试科目 id
	 * @param examId
	 * @return
	 */
	@GetMapping("selectMSubjectByExamId/{examId}")
	public Map selectMSubjectByExamId(@PathVariable("examId")Integer examId) {
		return settingScoreService.selectMSubjectByExamId(examId);
	}
	
	/**
	 * 添加阅卷人查询列表
	 * @param schId
	 * @param subId
	 * @param teaNm
	 * @return
	 */
	@GetMapping("selectUTeacherBySchIdAndSubIdAndTeaNmLike")  
	public Map<String, Object> selectUTeacherBySchIdAndSubIdAndStuNmLike(Integer schId,Integer subId,String teaNm){
		return userCenterScoreService.selectUTeacherBySchIdAndSubIdAndStuNmLike(schId, subId, teaNm);
	}
	
	@PostMapping("insertMExamMarker")
	public Map insertMExamMarker(@RequestBody MExamMarker mExamMarker) {
		return settingScoreService.insertMExamMarker( mExamMarker);
	}
	
	
	
	 /**
	  * 分解阅卷任务
	  * @param examId
	  * @param examSubId
	  * @param topicNo
	  * @param markerId
	  * @return
	  */
	@PostMapping("ExamResolve")
	public Map ExamResolve(Integer examId, Integer examSubId, Integer oldMarkerId,
			Integer topicCount, Integer topicNo, Integer newMarkerId) {
		HashMap<String, Object> map = new HashMap<String, Object>();
		Integer result = progressCheckService.ExamResolve(examId, examSubId, oldMarkerId, topicCount, topicNo, newMarkerId, settingScoreService);
		System.out.println(result);
		if(result == 1 ) {
			map.put("code", 1001);
			map.put("result", result);
		}else {
			map.put("code", 10013);
			map.put("result", null);
		}
		
		return map;
	}
	
	/**
	 * 分解阅卷任务的候选人列表
	 * @return
	 */
	@GetMapping("selectExamTeaCandidate/{examId}/{examSubId}/{topicNo}")
	public Map selectExamTeaCandidate(@PathVariable("examId")Integer examId,@PathVariable("examSubId")Integer examSubId,@PathVariable("topicNo")Integer topicNo) {
		return settingScoreService.selectExamTeaCandidate(examId, examSubId, topicNo);
	}
	
	
}
